<?php

// 团购商品管理

namespace app\console\controller;

use think\Controller;
use app\console\model\GroupGoods as GroupGoodsModel;
use think\Db;
use think\Request;

class GroupGoods extends Controller
{

    public function index(Request $request, GroupGoodsModel $groupGoods)
    {
        // 获取参数
        $inquire = $request->instance()->param();

        // 筛选条件
        $condition['id'] = ['eq', 0];
        if (!empty($inquire['title'])) $condition['title'] = ['like', '%' . $inquire['title'] . '%'];

        // 获取数据
        $data = $groupGoods->with('ShopGoods,Shop')->where($condition)->paginate(12, false, ['query' => $inquire]);

        // $data = Db::view('group_goods','*')->view('shop_goods','title,price as s_price,id','group_goods.goods_id')
        //     ->where($condition)->paginate(12, false, ['query' => $inquire]);



        return $this->fetch('', [
            "mate_title" => '团购商品',
            'data'       => $data
        ]);
    }
}